Imports System.Collections

Partial Class pages_producttypes_usercontrols_UCProductType : Inherits UserControl

#Region "Members"
    Private m_productType As CProductType
    Private m_sortedList As IList
#End Region

#Region "Interface"
    Public Sub Display(ByVal [productType] As CProductType, sortedList as IList)
        If Parent.Controls.Count Mod 2 = 0 Then row.Attributes.Add("class", "alt_row")

        m_productType = [productType]
        m_sortedList = sortedList

        colAddDelete.Visible = CSession.IsDeveloper

        With m_productType
            litNumber.Text = CStr(sortedList.IndexOf(m_productType) + 1)
            lnkTypeName.Text =  CStr(IIF(.TypeName.Length = 0, "...", .TypeName))
            lnkTypeName.NavigateUrl = CSitemap.ProductTypeEdit(.TypeId)

            If .TypeParentTypeId > 0 Then litTypeParentTypeId.Text = .ParentType.TypeName
            chkTypeParentIsRequired.Checked = .TypeParentIsRequired
            chkTypeIsFree.Checked = .TypeIsFree
            chkTypeCanHaveAudio.Checked = .TypeCanHaveAudio
            chkTypeCanHavePdfOrWord.Checked = .TypeCanHavePdfOrWord
            chkTypeCanHaveHtmlNotesOrPreview.Checked = .TypeCanHaveHtmlNotesOrPreview
            chkTypeCanHaveVimeo.Checked = .TypeCanHaveVimeo
            chkTypeCanHaveTranscript.Checked = .TypeCanHaveTranscript
            litTypeDescription.Text = .TypeDescription

            If Not CSession.IsDeveloper Then
                lnkTypeName.Enabled = False
                chkTypeCanHaveAudio.Enabled = False
                chkTypeCanHaveHtmlNotesOrPreview.Enabled = False
                chkTypeCanHaveHtmlNotesOrPreview.Enabled = False
                chkTypeCanHavePdfOrWord.Enabled = False
                chkTypeCanHaveTranscript.Enabled = False
                chkTypeCanHaveVimeo.Enabled = False
                chkTypeIsFree.Enabled = False
                chkTypeParentIsRequired.Enabled = False
            End If
        End With
    End Sub
#End Region

#Region "Event Handlers"
    Private Sub chkTypeParentIsRequired_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkTypeParentIsRequired.CheckedChanged
        With m_productType
            .TypeParentIsRequired = chkTypeParentIsRequired.Checked
            .Save()
        End With
        Refresh()
    End Sub
    Private Sub chkTypeIsFree_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkTypeIsFree.CheckedChanged
        With m_productType
            .TypeIsFree = chkTypeIsFree.Checked
            .Save()
        End With
        Refresh()
    End Sub
    Private Sub chkTypeCanHaveAudio_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkTypeCanHaveAudio.CheckedChanged
        With m_productType
            .TypeCanHaveAudio = chkTypeCanHaveAudio.Checked
            .Save()
        End With
        Refresh()
    End Sub
    Private Sub chkTypeCanHavePdfOrWord_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkTypeCanHavePdfOrWord.CheckedChanged
        With m_productType
            .TypeCanHavePdfOrWord = chkTypeCanHavePdfOrWord.Checked
            .Save()
        End With
        Refresh()
    End Sub
    Private Sub chkTypeCanHaveHtmlNotesOrPreview_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkTypeCanHaveHtmlNotesOrPreview.CheckedChanged
        With m_productType
            .TypeCanHaveHtmlNotesOrPreview = chkTypeCanHaveHtmlNotesOrPreview.Checked
            .Save()
        End With
        Refresh()
    End Sub
    Private Sub chkTypeCanHaveVimeo_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkTypeCanHaveVimeo.CheckedChanged
        With m_productType
            .TypeCanHaveVimeo = chkTypeCanHaveVimeo.Checked
            .Save()
        End With
        Refresh()
    End Sub
    Private Sub chkTypeCanHaveTranscript_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkTypeCanHaveTranscript.CheckedChanged
        With m_productType
            .TypeCanHaveTranscript = chkTypeCanHaveTranscript.Checked
            .Save()
        End With
        Refresh()
    End Sub
    Private Sub btnDelete_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnDelete.Click
        m_productType.Delete()
        Refresh()
    End Sub
#End Region

#Region "Private"
    Private Sub Refresh()
        'CCache.ClearCache()

        'If False Then 'Request.RawUrl.ToLower.Contains("myparent.aspx") Then
        '    'Special case: Parent entity owns the list
        '    Response.Redirect(CSitemap.MyParentEdit(m_productType.ProductTypeParentId, MyParent.ETab.producttypes, m_pageIndex)
        'Else
        '    'Normal case: Search page owns the list
            Response.Redirect(Request.RawUrl) 'includes paging info
        'End If 
    End Sub
#End Region

End Class
